package org.systemsbiology.addama.sequencing.util;

import java.io.*;
import java.util.Date;
import java.util.StringTokenizer;

/**
 * Created by IntelliJ IDEA.
 * User: jlin
 * Date: Sep 14, 2010
 * Time: 4:21:39 PM
 * To change this template use File | Settings | File Templates.
 */
public class SNPChangesFile {
    public static void main(String[] args) {

        String keyLine = "";
        String strLine = "";

        try {
            FileInputStream fstream = new FileInputStream("/Users/jlin/Desktop/Archive/YSEQ4_YO502_changes.tsv");
            StringBuffer sb = new StringBuffer();
            // Get the object of DataInputStream
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            //Read File Line By Line
            System.out.println(new Date());
            while ((strLine = br.readLine()) != null) {


                StringTokenizer tko = new StringTokenizer(strLine, "\t");
                String[] tk = strLine.split("\t");

                if (tk.length >= 10) {
                    final String chrom = tk[2];
                    final int ref_start = Integer.parseInt(tk[3]);
                    final int ref_end = Integer.parseInt(tk[4]);
                    final String ref_name = "lookup from chromosome";
                    final String ref_seq = tk[5];
                    final String mod_seq = tk[6];
                    final int mod_start = Integer.parseInt(tk[7]);
                    final int mod_end = Integer.parseInt(tk[8]);
                    final double score = Double.parseDouble(tk[9]);
                    System.out.println("chrom " + chrom + " score " + score);
                } else {
                    System.err.println(tko.countTokens() + "line with less than 10 tokens:" + strLine + " how many splitted arrays:" + tk.length);
                }
                 if (tko.countTokens() >= 10) {
                    //System.out.println(tko.countTokens() + ">= 10 tokens:" + strLine + " how many splitted arrays:" + tk.length);

                } else {
                    System.err.println(tko.countTokens() + "line with less than 10 tokens:" + strLine + " how many splitted arrays:" + tk.length);
                }

            }
            //Close the input stream
            in.close();
            //out.close();

        } catch (Exception e) {//Catch exception if any
            System.out.println("Error: " + e.getMessage() + " KeyLine:" + keyLine + " line:" + strLine);
            e.printStackTrace();
        }

    }
}
